<?php 
/**
 * 用户租相关操作
 * @package User
 * @author chengtao
 */
class Group extends Think{
	private $Group = '';
	private $page_count = '15';
	public function __construct(){
		$this->Group = D('role');
	}
	public function getGroupList(){
		$field = "travel_role.*,travel_user.email";
		$order = "travel_role.id";
		$this->Group->join('travel_user ON travel_user.id=travel_role.create_uid');
		$where = "1";
		$group_list = $this->Group->where($where)->order($order)->field($field)->select();
		//echo $this->Group->getlastsql();
		return $group_list;
		
	}
	public function update(){
		$id = $_POST['id'];
		$_POST['update_time'] = $_SERVER['REQUEST_TIME'];
		if($this->Group->where("id = {$id}")->save($_POST)){
			echo '修改成功';
		}else{
			echo '<br/>',$this->Group->getlastsql(),'<br/>';
			echo $this->Group->geterror();
		}
	}
	public function getGroupInfo(){
		$gid = $_GET['id'];
		$where = "travel_role.id = $gid";
		$field = "travel_role.*,COUNT(travel_role_user.role_id) AS `count` ";
		$join  = "JOIN travel_role_user ON travel_role_user.role_id = travel_role.id";
		
		
		$group_info = $this->Group->join($join)->where($where)->field($field)->where($where)->find();
		return $group_info;
	}
	public function add(){
		if($this->Group->create()){
			$this->Group->add();
		}else{
			echo '添加失败！';
		}
	}
	/**
	 * 返回制定用户组所持有的权限id
	 * @param  $gid 用户组id
	 */
	public function getGroupAuth(){
		$gid = $_GET['id'];
		$Access = M('access');
		$result = array();
		$node_list = $Access->field('node_id')->where("role_id={$gid}")->select();
		foreach($node_list as $v)$result[]=$v['node_id'];
		//dump($result);
		return $result;
	}

	
	
	
}